package service

import (
	"context"
	pb "driver/api/driver/v1"
	"driver/internal/biz"
	"fmt"
)

type DriverService struct {
	pb.UnimplementedDriverServer
	uc *biz.GreeterUsecase
}

func NewDriverService(uc *biz.GreeterUsecase) *DriverService {
	return &DriverService{
		uc: uc,
	}
}

func (s *DriverService) ListDrvier(ctx context.Context, req *pb.ListDrvierRequest) (*pb.ListDrvierReply, error) {

	var vehicleuser biz.VehicleUser
	list, err := vehicleuser.VehicleList(int(req.Page), int(req.PageSize), req.Name)
	if err != nil {
		return nil, err
	}

	var vehicleuserList []*pb.VehicleUser
	for _, i := range list {
		vehicleuserList = append(vehicleuserList, &pb.VehicleUser{
			Name:         i.Name,
			Phone:        i.Phone,
			IdCard:       i.IdCard,
			PlateNumber:  i.PlateNumber,
			ResidentCity: i.ResidentCity,
			Status:       i.Status,
		})
	}

	return &pb.ListDrvierReply{
		List: vehicleuserList,
	}, nil
}
func (s *DriverService) ShowDriverVehicle(ctx context.Context, req *pb.ShowDriverVehiclequest) (*pb.ShowDriverVehicleReply, error) {

	var show biz.DriverVehicle
	show.ID = uint(req.ID)

	if err := show.ShowDriverVehicle(); err != nil {
		return nil, fmt.Errorf("详情查询失败")
	}
	return &pb.ShowDriverVehicleReply{
		Name:               show.Name,
		Gender:             show.Gender,
		Education:          show.Education,
		ResidentCity:       show.ResidentCity,
		IdType:             show.IdType,
		IdNumber:           show.IdNumber,
		IdFrontImg:         show.IdFrontImg,
		IdHandheldImg:      show.IdHandheldImg,
		IdBackImg:          show.IdBackImg,
		PlateNumber:        show.PlateNumber,
		VehicleOwner:       show.VehicleOwner,
		VehicleBrand:       show.VehicleBrand,
		VehicleModel:       show.VehicleModel,
		VehicleColor:       show.VehicleColor,
		VehicleLicenseInfo: show.VehicleLicenseInfo,
		VehicleImgs:        show.VehicleImgs,
	}, nil
}
